#include<bits/stdc++.h>
using namespace std;
list<int>lst;
list<int>tmp = {10 , 20 , 30 , 40};
int main(){
	for(int i = 1 ; i <= 7 ; i++){
		lst.push_back(i);
	}
	lst.push_front(8);
	for(auto it = lst.begin() ; it != lst.end() ; it++){
		cout << *it << " ";
	}
	cout << endl;
	auto it = lst.begin();
	it++;
	lst.splice(it , tmp);
	for(auto it = lst.begin() ; it != lst.end() ; it++){
		cout << *it << " ";
	}
	it = lst.end();
	lst.erase(--it);
	for(auto it = lst.begin() ; it != lst.end() ; it++){
		cout << *it << " ";
	}
	cout << endl << lst.size() << endl;
	return 0;
}
